package com.hc.util.snmp.impl;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.snmp4j.smi.OID;

import com.hc.util.snmp.SNMPServer;

public class SNMPServerImpl implements SNMPServer{
	String target = "192.168.0.220/161";
	
	@Override
	public void setTarget(String target) {
		this.target = target;
	}
	
	
	@Override
	public Object get(String oid) {
		try {
			return SnmpInstance.getInstance().getPDU(target, oid);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Map<String, Object> get(Map<String, Object> oids) {
		try {
			SnmpInstance.getInstance().getPDUs(target, oids);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Object set(String oid, Object value) {
		try {
			return SnmpInstance.getInstance().setPDU(target, oid, value);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Map<String, Object> set(Map<String, Object> oids) {
		try {
			SnmpInstance.getInstance().setPDUs(target, oids);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public List<Map<String, Object>> getTable(String oid) {
		Map<Integer, Map<String, Object>> datas = new HashMap<Integer, Map<String, Object>>();
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		try {
			SnmpInstance.getInstance().snmpGetBulk(datas, list, new OID(oid), target, oid);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return list;
	}

}
